jQuery(document).ready(function() {
    for (var i = 1; i < 9; i++) {
        document.getElementById("dim" + i).style.display = "none";
    }
});

function doTypeDropDownWork(sender, languageName) {
    /// Żeby dodać element do TypeDropDown wystarczy dodać wartość do tablicy TypeArray.
    var style = sender.value;
    var typeDropDown = document.getElementById("typeDropDown");
    // czyszczenie listy
    for (var i = 2; i < typeDropDown.length; i++) {
        typeDropDown.remove(i);
    }
    jQuery(".dimensionsInputs").children().css('display', 'none');
        switch (style) {
        case 'air':
            var TypeArray = new Array(getTranslation('sizeAir1', languageName), getTranslation('sizeAir2', languageName), getTranslation('sizeAir3', languageName));
            for (var i = 1; i < TypeArray.length + 1; i++) {
                typeDropDown.options[i] = new Option(TypeArray[i - 1], "air" + i);
            }
            break;
        case 'oil':
            var TypeArray = new Array(getTranslation('sizeOil1', languageName), getTranslation('sizeOil2', languageName));
            for (var i = 1; i < TypeArray.length + 1; i++) {
                typeDropDown.options[i] = new Option(TypeArray[i - 1], "oil" + i);
            }
            break;
        case 'fuel':
            var TypeArray = new Array(getTranslation('sizeFuel1', languageName), getTranslation('sizeFuel2', languageName), getTranslation('sizeFuel3', languageName), getTranslation('sizeFuel4', languageName));
            for (var i = 1; i < TypeArray.length + 1; i++) {
                typeDropDown.options[i] = new Option(TypeArray[i - 1], "fuel" + i);
            }
            break;
        case 'cabin':
            var TypeArray = new Array(getTranslation('sizeCabin1', languageName), getTranslation('sizeCabin2', languageName));
            for (var i = 1; i < TypeArray.length + 1; i++) {
                typeDropDown.options[i] = new Option(TypeArray[i - 1], "cabin" + i);
            }
            break;
    }
	document.getElementById("searchButtonSizes").style.display = "none";
}

function recognizeDimensions(sender) {
    clearInputs();
    switch (sender.value) {
        case 'air1':
            jQuery('.sizesSamplePhoto').html('<img src="Content/images/sizes/1_1.jpg" alt="air" />');
            break;
        case 'air2':
            jQuery('.sizesSamplePhoto').html('<img src="Content/images/sizes/1_2.jpg" alt="air" />');
            break;
        case 'air3':
            jQuery('.sizesSamplePhoto').html('<img src="Content/images/sizes/1_3.jpg" alt="air" />');
            break;

        case 'oil1':
            jQuery('.sizesSamplePhoto').html('<img src="Content/images/sizes/2_1.jpg" alt="oil" />');
            break;
        case 'oil2':
            jQuery('.sizesSamplePhoto').html('<img src="Content/images/sizes/2_2.jpg" alt="oil" />');
            break;

        case 'fuel1':
            jQuery('.sizesSamplePhoto').html('<img src="Content/images/sizes/3_1.jpg" alt="fuel" />');
            break;
        case 'fuel2':
            jQuery('.sizesSamplePhoto').html('<img src="Content/images/sizes/3_2.jpg" alt="fuel" />');
            break;
        case 'fuel3':
            jQuery('.sizesSamplePhoto').html('<img src="Content/images/sizes/3_3.jpg" alt="fuel" />');
            break;
        case 'fuel4':
            jQuery('.sizesSamplePhoto').html('<img src="Content/images/sizes/3_4.jpg" alt="fuel" />');
            break;

        case 'cabin1':
            jQuery('.sizesSamplePhoto').html('<img src="Content/images/sizes/4_1.jpg" alt="cabin" />');
            break;
        case 'cabin2':
            jQuery('.sizesSamplePhoto').html('<img src="Content/images/sizes/4_2.jpg" alt="cabin" />');
            break;
    }
    
    var d = document;
    var styleValue = sender.value;
    var senderArray = new Array();
	var searchButton = d.getElementById("searchButtonSizes");
    senderArray['air1'] = 'ABH'
    senderArray['air2'] = 'ABCDH'
    senderArray['air3'] = 'ABCDH';
    senderArray['oil1'] = 'ABCH';
    senderArray['oil2'] = 'ABCGH';
    senderArray['fuel1'] = 'ABCH';
    senderArray['fuel2'] = 'ABCFGH';
    senderArray['fuel3'] = 'AFGH';
    senderArray['fuel4'] = 'AFGH';
    senderArray['cabin1'] = 'ABH';
    senderArray['cabin2'] = 'ABH';
	senderArray[''] = '';
    
    /// referencje do poszczególnych bloków przechowuję w tablicy, kolejno:
    /// wymiar A = dimensions[1]
    /// ...
    /// wymiar H = dimensions[8]
    
    var dimensions = new Array(7);
    for (var i = 1; i < 9; i++) {
        dimensions[i] = d.getElementById("dim" + i);
        dimensions[i].style.display = "none";
    }
    
    /// wyświetlanie odpowiednich bloków
    var dimensionsToActivate = senderArray[styleValue];
    for (var i = 0; i < dimensionsToActivate.length; i++) {
        var singleDimension = dimensionsToActivate.substr(i, 1);
        var charToInt = singleDimension.charCodeAt(0) - 64;
        d.getElementById("dim" + charToInt).style.display = "block";
    }
	
	if (styleValue != "") {
        searchButton.style.display = "block";
    }
    else {
        searchButton.style.display = "none";
    }

}

function clearInputs() {
    jQuery("#dimAtext").val('');
    jQuery("#dimBtext").val('');
    jQuery("#dimCtext").val('');
    jQuery("#dimDtext").val('');
    jQuery("#dimEtext").val('');
    jQuery("#dimFtext").val('');
    jQuery("#dimGtext").val('');
    jQuery("#dimHtext").val('');
}